<?php
/**
*  +----------------------------------------------------------------------------------------------+
*   | Explain:
*  +----------------------------------------------------------------------------------------------+
*   | Author: ONLY <491518132@qq.com>
*	+----------------------------------------------------------------------------------------------+
*   | Creater Time : 2014-1-3 	
*  +----------------------------------------------------------------------------------------------+
*   | Link :		http://www.phpyrb.com	     
*  +----------------------------------------------------------------------------------------------+
**/

	class Statistics {
		protected $userid;
		public function __construct($_userid){
			$_userid ? $this->userid = $_userid : exit('请传入用户ID');
		}
		
		
		function coupon($_userid,$_effective = true){
			$model = M('UserCoupon');
			$where = array();
			$where['userid'] = $_userid;
		}
		
		/**
		* 根据ID返回账户财务信息
		* @param string platform 平台 
		* @return array $info
		* @author MaWei (http://www.phpyrb.com)
		* @date 2014-1-3下午5:27:18j
		*/
		function account_info($_platform = 'SMW01'){
			$model = M('UserMoney');
			$info = $model->where(array('userid'=>$this->userid,'platform'=>$_platform))->select();
			$info = field2key($info, 'subject');
			foreach ($info  as $k => $v){
				$info[$k]['value'] = $v['value'] * 0.01;
			}
			return $info;
		}
		
		/**
		* 返回订单常用统计
		* @return array $count
		* @author MaWei (http://www.phpyrb.com)
		* @date 2014-1-7下午2:29:09
		*/
		function base_order_count(){
			$count = array();
			//已发货 / 待收货订单
			$count['shipping_status'] = $this->order_effective(array('shipping_status' => '1'));
			//未支付 / 待支付订单
			$count['pay_status'] = $this->order_effective(array('pay_status' => '0'));
			//已完成 / 已成交订单
			$count['status'] = $this->order_effective(array('status' => '10'));
			return $count;
		}
		
		/**
		* 返回订单的状态数量
		* @param array $where 传你要查询的状态数组值 如： array('status'=>10);
		* @return int $count
		* @author MaWei (http://www.phpyrb.com)
		* @date 2014-1-7下午2:14:06
		*/
		function order_effective($_where = array() ,$_platform = 'SMW01'){
			$model = M('Order');
			$where = array();
			$where['userid'] = $this->userid;
			$where = array_merge($where,$_where);
			$count = $model->where($where)->count('id');
			return $count;
		}
	}